from routers.core.Gzip import register_gzip_request
from fastapi import APIRouter, Body, Depends, Request
from routers.core.Auth import (
    AlterState,
    authorize,
)
from utils.exception import ResponseException
from core.basic.mcharacter import createCharacter
from routers.core.Response import response

appRouter = APIRouter()

register_gzip_request(appRouter)

@appRouter.post(path="/calc")
async def calc(request: Request, params=Body(None), state: AlterState = Depends(authorize)):
    alter = None
    if (state  is None or state.alter  is None):
        raise ResponseException("登录过期或无效Token，请刷新后重试")
    else:
        alter = state.alter
        equversion = state.equVersion
    character = createCharacter(alter, equversion)
    info = character.calc(params)
    info['token'] = state.token
    return response(data=info)